package com.wushijia.io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.Channel;
import java.nio.channels.FileChannel;

public class FileIoTest {

	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		File file = new File("C:/QQDownload");
		File[] files = file.listFiles();
		for(File file2:files){
			if(file2.getName().indexOf("021415_028")>-1
					||file2.getName().indexOf("010315-773")>-1
					||file2.getName().indexOf("013115-797")>-1
					||file2.getName().indexOf("HEYZO-0821")>-1
					||file2.getName().indexOf("CWP-117")>-1
					||file2.getName().indexOf("MKD-S121")>-1
					||file2.getName().indexOf("LAF-44")>-1
					||file2.getName().indexOf("LAF-59")>-1
					||file2.getName().indexOf("SMD-127")>-1){
				System.out.println(file2.getName());
			}
			//System.out.println(file2.getName());
		}
		// TODO Auto-generated method stub
		/*StringBuffer buffer = new StringBuffer();
		try {
			FileReader fileReader = new FileReader("d:\\LOLCfg.ini");
			File file = new File("d:/LOLCfg.ini");
			FileInputStream fileInputStream = new FileInputStream(file);
			FileDescriptor descriptor = new FileDescriptor();
			descriptor.sync();
			char[] c = new char[1024];
			int len;
			while((len = fileReader.read(c)) > 0){
				buffer.append(new String(c,0,len));
			}
			System.out.println(buffer.toString());
			File file = new File("d:\\test.txt");
			InputStream input = new FileInputStream(file); // get the InputStream from the client socket
			BufferedReader reader = new BufferedReader(new InputStreamReader(input));
			String nameLine = "";
			while ((nameLine = reader.readLine()) != null) {
				System.out.println(nameLine);
			}
			
			
			//�ļ��ܵ�����ȡ
			RandomAccessFile aFile = new RandomAccessFile("d:\\test.txt", "rw");
			FileChannel inChannel = aFile.getChannel();
			ByteBuffer buf = ByteBuffer.allocate(48);
			int bytesRead = inChannel.read(buf);
			
			while (bytesRead != -1) {
				//System.out.println("Read " + bytesRead);
				buf.flip();
			while(buf.hasRemaining()){
				System.out.print((char) buf.get()+"����");
			}
				buf.clear();
				bytesRead = inChannel.read(buf);
			}
			aFile.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}

}
